#!/usr/bin/env bash

get_state() {
  xkblayout-state print %n | grep -Eo -e English -e Russian
}

get_caps_state() {
  xset -q | sed -n 's/^.*Caps Lock:\s*\(\S*\).*$/\1/p'
}

get_num_state() {
  xset q | grep -i num | cut -c 46-48
}

num=$(get_num_state)
caps=$(get_caps_state)
kb=$(get_state)
kbstate=""

case $kb in
  English)
    kbstate="en"
  ;;
  Russian)
    kbstate="ru"
  ;;
esac 2>/dev/null

echo -e "$kbstate"
